from copy import deepcopy
from zlib import crc32
from math import fabs

#Exp dolocen modulo
#TODO: doloci optimalno
HT_MODULO = 2**15;
HT_MODULO = 10

class HashTable:
  ht_level    = []
  ht_max      = 0
  ht_hmax      = 0
  ht_rnd      = 0
  ht_bufsize   = 0

  
  def __init__(self,maxsize, rnd):
    '''init hash table'''
    self.ht_rnd       = rnd
    self.ht_max       = maxsize*10**rnd
    self.ht_bufsize   = len(str(int(self.ht_max)))
    self.ht_hmax       = self.ht_max*10**(2*self.ht_bufsize)+self.ht_max*10**(self.ht_bufsize)+self.ht_max
    self.ht_level     = [[] for i in range(HT_MODULO)]

        
  def insert(self, in_pt):
    '''return0/1 on existing element'''
    target=str(in_pt[0])+str(in_pt[1])+str(in_pt[2])
    index = int(fabs(crc32(target))) % HT_MODULO
    r = self.ht_level[index].count(in_pt) > 0
    self.ht_level[index] = self.ht_level[index] + [in_pt]
    return r
    
  def dbgPrint(self):
    '''print hash table'''
    print self.ht_level
